package com.kx.center.service.impl;

import com.kx.center.entity.Brand;
import com.kx.center.entity.Company;
import com.kx.center.mappers.BrandMapper;
import com.kx.center.service.BrandService;
import com.kx.center.util.SQLUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by acmen on 16-1-3.
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Override
    public int addCompanyBrand(int companyId, Brand brand) {
        int addStatus = brandMapper.insertBrand(brand);
        return addStatus;
    }

    @Override
    public List<Brand> getCompanyBrandList(int companyId, int pageNum, int pageSize) {
        String order = "id desc";
        String limitStr = pageNum * pageSize +","+(pageSize+1);

        Map<String, Object> whereMap = new HashMap<String, Object>();
        whereMap.put("company_id",companyId);
        whereMap.put("status", 1);

        String where = "";
        where = SQLUtil.builWhere(whereMap);
        List<Brand> brandList = brandMapper.findBrandList(where, order, limitStr);

        if(brandList == null){
            brandList = new ArrayList<Brand>();
        }

        return brandList;
    }

	@Override
	public void updateBrand(Brand brand) {
		
		brandMapper.updateBrand(brand);
	}

	@Override
	public void deleteBrand(int id) {
		
		brandMapper.deleteBrand(id);
	}
}
